/**
 * 
 */
package com.orisper.esb.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.orisper.esb.service.ApiProductService;
import com.orisper.model.ApiMessage;
import com.orisper.utils.ApiConstants;
import com.orisper.utils.exception.ApiException;

import aos.framework.core.asset.WebCxt;
import aos.framework.core.typewrap.Dto;
import aos.framework.core.typewrap.Dtos;
import aos.framework.core.utils.AOSJson;
import aos.framework.core.utils.AOSUrlUtils;
import aos.framework.core.utils.AOSUtils;

/**
 * @author Administrator
 *
 */
@Controller
@RequestMapping(value = "api/product")
public class ApiProductController {
	
	@Autowired
	ApiProductService apiProductService;
	
	/**
	 * 查询分类列表
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "getCatalogyList")
	public void getCatalogyList(HttpServletRequest request, HttpServletResponse response){
		Dto inDto=Dtos.newInDto(request);
		ApiMessage msg=new ApiMessage();
		try {
			msg=apiProductService.getCatalogyList(inDto);
		} catch (ApiException e) {
			msg.setCode(e.getCode());
			msg.setMessage(e.getMessage());
		} catch (Exception e){
			e.printStackTrace();
			msg.setCode(ApiConstants.REQ_ERROR);
			msg.setMessage(ApiConstants.MSG_EXCEPTION);
		}finally {
			WebCxt.write(response, AOSJson.toJson(msg));
		}
		
	}

	/**
	 * 查询分类列表
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "getTypeList")
	public void getTypeList(HttpServletRequest request, HttpServletResponse response){
		Dto inDto=Dtos.newInDto(request);
		ApiMessage msg=new ApiMessage();
		try {
			msg=apiProductService.getTypeList(inDto);
		} catch (ApiException e) {
			msg.setCode(e.getCode());
			msg.setMessage(e.getMessage());
		} catch (Exception e){
			e.printStackTrace();
			msg.setCode(ApiConstants.REQ_ERROR);
			msg.setMessage(ApiConstants.MSG_EXCEPTION);
		}finally {
			WebCxt.write(response, AOSJson.toJson(msg));
		}
		
	}
	
	/**
	 * 查询产品列表
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "getProductList")
	public void getProductList(HttpServletRequest request, HttpServletResponse response){
		Dto inDto=Dtos.newInDto(request);
		ApiMessage msg=new ApiMessage();
		try {
			if(AOSUtils.isEmpty(inDto.getPageStart())){
				inDto.setPageStart(0);
			}
			if(AOSUtils.isEmpty(inDto.getPageLimit())){
				inDto.setPageLimit(6);
			}
			msg=apiProductService.getProductList(inDto);
		} catch (ApiException e) {
			msg.setCode(e.getCode());
			msg.setMessage(e.getMessage());
		} catch (Exception e){
			e.printStackTrace();
			msg.setCode(ApiConstants.REQ_ERROR);
			msg.setMessage(ApiConstants.MSG_EXCEPTION);
		}finally {
			WebCxt.write(response, AOSJson.toJson(msg));
		}
		
	}

	
	/**
	 * 产品详情
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "getProductDetail")
	public void getProductDetail(HttpServletRequest request, HttpServletResponse response){
		Dto inDto=Dtos.newInDto(request);
		ApiMessage msg=new ApiMessage();
		try {
			msg=apiProductService.getProductDetail(inDto);
		} catch (ApiException e) {
			msg.setCode(e.getCode());
			msg.setMessage(e.getMessage());
		} catch (Exception e){
			e.printStackTrace();
			msg.setCode(ApiConstants.REQ_ERROR);
			msg.setMessage(ApiConstants.MSG_EXCEPTION);
		}finally {
			WebCxt.write(response, AOSJson.toJson(msg));
		}
		
	}
	
	
}
